package io.netty.http;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.timeout.IdleStateHandler;

import java.util.concurrent.TimeUnit;

/**
 * @author Verlet
 * @date 2023-02-01 01:02
 */
public class NettyHttpServerChannelInitializer  extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) {
        ch.pipeline()
                // HTTP 编解码器
                .addLast(new HttpServerCodec())
                // 当IdleStateEvent 触发后，就会传递给管道的下一个handler 的userEventTriggered方法
                .addLast(new IdleStateHandler(3,5,7, TimeUnit.SECONDS))
                .addLast(new NettyHttpServerHandler());
    }
}
